package org.chw.callback.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;

/**
 * @ClassName: AsyncConfig
 * @Description: spring 线程配置
 * @Autor: Vincent.Chen
 * @Create: 2018/6/13 13:52
 * @Version: 1.0
 **/
@Configuration
@EnableAsync
public class AsyncConfig {
  private int corePoolSize = 10;
  private int maxPoolSize = 200;
  private int queueCapacity = 10;

  @Bean
  public Executor taskExecutor() {
    ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
    threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);
    threadPoolTaskExecutor.setQueueCapacity(queueCapacity);
    threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
    threadPoolTaskExecutor.initialize();
    return threadPoolTaskExecutor;
  }
}
